<template>
<div class="app">
<button @click="show=true">打开</button>
<button @click="backgroundColor='green'">修改</button>
<p v-if="show" v-backgroundColor='backgroundColor'>nhhh</p>
</div>
</template>

<script>
export default {
  data() {
    return {
      backgroundColor:'blue',
      show:false
    }
  },
  directives:{
    backgroundColor:{
    inserted(el,binding){
      el.style.backgroundColor=binding.value
    },
    update(el,binding) {
      el.style.backgroundColor=binding.value
    },
    }
  }
}
</script>

<style>
p{
  height: 300px;
  width: 300px;
  
}
</style>